package com.itqf.proxy;

import com.itqf.interceptor.UserInterceptor;
import com.itqf.service.UserService;
import net.sf.cglib.proxy.Enhancer;

/**
 * projectName: springframeworkgp8
 *
 * @author: 赵伟风
 * time: 2021/8/3 17:04
 * description:
 */
public class UseCGLib {

    public static void main(String[] args) {

        //1.创建拦截器对象
        UserInterceptor userInterceptor = new UserInterceptor();
        //2.创建代理对象生成器
        Enhancer enhancer = new Enhancer();
        //3.设置生成,模板
        enhancer.setSuperclass(UserService.class);
        //4.设置拦截器
        enhancer.setCallback(userInterceptor);

        //5.生成代理对象
        UserService userService = (UserService) enhancer.create();


        UserService userServicen = new UserService();


        userService.login();
        userServicen.login();

    }
}
